import { SysJobTrigger, SysJobDetail } from "@/api-services/models/system";
import { SqlSugarPagedList } from "@/api-services/unifyResult";
import { BaseApi } from "@/api-services/apis/baseApi";

/**
 * 认证服务
 */
class SysJobApi extends BaseApi {
  /// <summary>
  /// 获取作业分页列表
  /// </summary>
  getPageJobDetail = async (data: SysJobDetail.JobDetailPageInput) => {
    return await this.normalGet<SqlSugarPagedList<SysJobDetail.JobDetailOutput>>("/getPageJobDetail", data);
  };
  /// <summary>
  /// 根据作业id获取触发器列表
  /// </summary>
  getJobTriggerList = async (data: SysJobDetail.JobDetailIdInput) => {
    return await this.normalGet<Array<SysJobTrigger.SysJobTrigger>>("/getJobTriggerList", data);
  };
  /// <summary>
  /// 获取作业触发器运行记录分页列表
  /// </summary>
  getPageJobTriggerRecord = async (data: SysJobTrigger.JobTriggerRecordPageInput) => {
    return await this.normalGet<SqlSugarPagedList<SysJobTrigger.SysJobTriggerRecord>>("/getPageJobTriggerRecord", data);
  };
  /// <summary>
  /// 添加作业
  /// </summary>
  addJobDetail = async (data: SysJobDetail.JobDetailInput) => {
    await this.normalPost("/addJobDetail", data);
  };
  /// <summary>
  /// 更新作业
  /// </summary>
  updateJobDetail = async (data: SysJobDetail.JobDetailInput) => {
    await this.normalPost("/updateJobDetail", data);
  };
  /// <summary>
  /// 删除作业
  /// </summary>
  deleteJobDetail = async (data: SysJobDetail.JobDetailIdInput) => {
    await this.normalPost("/deleteJobDetail", data);
  };
  /// <summary>
  /// 添加触发器
  /// </summary>
  // addJobTrigger = async (data: SysJobTrigger) => {
  //   await this.normalPost("/addJobTrigger", data);
  // };
  /// <summary>
  /// 更新触发器
  /// </summary>
  // updateJobTrigger = async (data: SysJobTrigger.JobTriggerIdInput) => {
  //   await this.normalPost("/updateJobTrigger", data);
  // };
  /// <summary>
  /// 删除触发器
  /// </summary>
  deleteJobTrigger = async (data: SysJobTrigger.JobTriggerIdInput) => {
    await this.normalPost("/deleteJobTrigger", data);
  };
  /// <summary>
  /// 暂停所有作业
  /// </summary>
  pauseAllJob = async () => {
    this.normalPost("/pauseAllJob", null);
  };
  /// <summary>
  /// 启动所有作业
  /// </summary>
  startAllJob = async () => {
    this.normalPost("/startAllJob", null);
  };
  /// <summary>
  /// 暂停作业
  /// </summary>
  pauseJob = async (data: SysJobDetail.JobDetailIdInput) => {
    this.normalPost("/pauseJob", data);
  };
  /// <summary>
  /// 启动作业
  /// </summary>
  startJob = async (data: SysJobDetail.JobDetailIdInput) => {
    this.normalPost("/startJob", data);
  };
  /// <summary>
  /// 取消作业
  /// </summary>
  cancelJob = async (data: SysJobDetail.JobDetailIdInput) => {
    this.normalPost("/cancelJob", data);
  };
  /// <summary>
  /// 执行作业
  /// </summary>
  runJob = async (data: SysJobDetail.JobDetailIdInput) => {
    this.normalPost("/runJob", data);
  };
  /// <summary>
  /// 暂停触发器
  /// </summary>
  pauseTrigger = async (data: SysJobTrigger.JobTriggerIdInput) => {
    this.normalPost("/pauseTrigger", data);
  };
  /// <summary>
  /// 启动触发器
  /// </summary>
  startTrigger = async (data: SysJobTrigger.JobTriggerIdInput) => {
    this.normalPost("/startTrigger", data);
  };
  /// <summary>
  /// 强制唤醒作业调度器
  /// </summary>
  cancelSleep = async () => {
    this.normalPost("/cancelSleep", null);
  };
  /// <summary>
  /// 强制触发所有作业持久化
  /// </summary>
  persistAll = async () => {
    this.normalPost("/persistAll", null);
  };
}

export default new SysJobApi("/system/job");
